package cn.droidlover.xrecyclerview.demo.slice;

import cn.droidlover.xrecyclerview.demo.ResourceTable;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.app.Context;

/**
 * Loading的页面
 */
public class LoadingComponent extends DependentLayout {
    private AnimatorProperty mAnimator;
    private Image mImage;

    public LoadingComponent(Context context) {
        super(context);
        setupComponent(context);
    }

    private void setupComponent(Context context) {

        LayoutScatter.getInstance(context).parse(ResourceTable.Layout_loading_component, this, true);
        mImage = (Image) findComponentById(ResourceTable.Id_image);
        mAnimator = mImage.createAnimatorProperty();


    }


    public void startLoading() {
        mAnimator.setDuration(600).rotate(360).setLoopedCount(AnimatorProperty.INFINITE).setTarget(mImage).start();
    }

    public void stopLoading() {
        mAnimator.cancel();
    }

}
